package Controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import DAO.TerminalDao;
import POJO.Terminal;

@Controller
@RequestMapping(value="terminal")
public class TerminalController {
	//本类里的所有方法会被terminalFilter过滤
	static Logger logger = Logger.getLogger(TerminalController.class);
	
	@Autowired
	private TerminalDao terminalDao;
	
	@RequestMapping("dataWrite")
	@ResponseBody
	public Map<String,String> dataWrite(@RequestParam("leftBalance")String leftBalance,
										@RequestParam("useFlow")String useFlow,
										@RequestParam("leftFlow")String leftFlow,
										@RequestParam("Type")String Type,
										HttpSession httpSession){
		
		HashMap<String,String> response=new HashMap<String,String>();
		boolean result=false;
		if(Type.equals("1")){
			Terminal terminal=(Terminal)httpSession.getAttribute("terminal");
			result=terminalDao.update3GFlow(leftBalance, useFlow, leftFlow, terminal);
		}
		if(result){
			response.put("result", "0");
		}else{
			response.put("result", "1");
		}
		return response;
	}


}
